package com.hsy.linemoney.modules.my.myaccount;

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.deparse.dpframe.tools.utils.DPLogUtil;
import com.hsy.linemoney.R;
import com.hsy.linemoney.apiservice.LineMoneyContext;
import com.hsy.linemoney.modules.common.CommonBaseActivityWithSimpleActionBar;
import com.hsy.linemoney.utils.CommonUtils;

/**
 * 我的账户 - 目前只有网页
 * Created by Administrator on 2016/7/12.
 */
public class MyAccountActivity extends CommonBaseActivityWithSimpleActionBar {
    //    private ListView listView;
//    private LayoutInflater inflater;
//    private List<String> listData = new ArrayList<>();
//    private Adapter adapter;
//    private LinearLayout add_account;
//
//    @Override
//    public int getRightbuttonIconResId() {
//        return R.mipmap.ic_exchange_add_receiver;
//    }
//
//    @Override
//    public boolean onActionBarRightButtonClicked(ImageButton rightButton) {
//        new AlertDialog.Builder(MyAccountActivity.this).setItems(
//                new String[]{getString(R.string.my_account_add_dialog_unrecever), getString(R.string.my_account_add_dialog_recever)}, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        startActivity(AddAccountActivity.class, String.valueOf(which + 1));
//                        dialog.dismiss();
//                    }
//                }).show();
//        return true;
//    }
//
//    @Override
//    public void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setTitle(R.string.title_my_account);
//        setContentView(R.layout.activity_my_account);
//        inflater = LayoutInflater.from(this);
//        add_account = F(R.id.add_account);
//        listView = F(R.id.listView);
//        for (int i = 0; i < 4; i++) {
//            listData.add("1000" + i);
//        }
//        if (null != listData && listData.size() != 0) {
//
//            adapter = new Adapter();
//            listView.setAdapter(adapter);
//        } else {
//            listView.setVisibility(View.GONE);
//        }
//        add_account.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                new AlertDialog.Builder(MyAccountActivity.this).setItems(
//                        new String[]{getString(R.string.my_account_add_dialog_unrecever), getString(R.string.my_account_add_dialog_recever)}, new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                startActivity(CreateReceiveAccountActivity.class, String.valueOf(which + 1));
//                                dialog.dismiss();
//                            }
//                        }).show();
//
//
//            }
//        });
//        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                startActivity(CreateReceiveAccountActivity.class, "3");
//            }
//        });
//
//        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
//            @Override
//            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
//
//                final Dialog builder = new AlertDialog.Builder(MyAccountActivity.this).create();
//                builder.setCancelable(false);
//                builder.show();
//                LayoutInflater layoutInflater = LayoutInflater.from(MyAccountActivity.this);
//                View view1 = layoutInflater.inflate(R.layout.dialog_delete, null);
//                TextView cancel = (TextView) view1.findViewById(R.id.cancel);
//                TextView ok = (TextView) view1.findViewById(R.id.ok);
//                builder.setContentView(view1);
//
//                cancel.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        builder.dismiss();
//                    }
//                });
//                ok.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        builder.dismiss();
//
//                        listData.remove(position);
//
//                        adapter.notifyDataSetChanged();
//                    }
//                });
//
//                return false;
//            }
//        });
//    }
//
//    private class Adapter extends BaseAdapter {
//
//        @Override
//        public int getCount() {
//            return listData.size();
//        }
//
//        @Override
//        public Object getItem(int position) {
//            return listData.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup parent) {
//            convertView = inflater.inflate(R.layout.item_my_account_list, null);
//            return convertView;
//        }
//    }
    private WebView webView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_team);
        setTitle(R.string.title_my_account);
        CommonUtils.showProgressDialog(this);
        webView = (WebView) findViewById(R.id.web_view);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setJavaScriptEnabled(true);
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress >= 100) {
                    CommonUtils.hideProgressDialog();
//                    showToast("请在此处登录一次");
                }
            }
        });
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                DPLogUtil.d("url=" + url);
                return true;
            }
        });
//        settings.setAppCacheEnabled(true);
        webView.loadUrl(LineMoneyContext.getServer() + "group/control_panel/manage?p_p_auth=heGWPmRP&p_p_id=2&p_p_lifecycle=0&p_p_state=maximized&doAsGroupId=20201&refererPlid=20548");
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (KeyEvent.KEYCODE_BACK == event.getKeyCode() && KeyEvent.ACTION_UP == event.getAction() && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.dispatchKeyEvent(event);
    }
}
